﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Elements
{
    public partial class strechDialog : Form
    {
        public strechDialog()
        {
            InitializeComponent();
        }

        //确定
        private void btnOk_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        //取消
        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        //预览
        private void btnScan_Click(object sender, EventArgs e)
        {
            var g = pictureBox1.CreateGraphics();
            var pen1 = new Pen(Color.Blue);
            g.Clear(BackColor);
            var p0 = new Point(0, 0);
            var p1 = new Point(0, 0);
            var p2 = new Point(0, 0);
            var p3 = new Point(0, 0);

            var x1 = 2 * Convert.ToInt32(txtX1.Text.Trim());
            var y1 = 2 * Convert.ToInt32(txtY1.Text.Trim());
            var x2 = 2 * Convert.ToInt32(txtX2.Text.Trim());
            var y2 = 2 * Convert.ToInt32(txtY2.Text.Trim());

            p0.X = 0;
            p0.Y = 510;
            p1.X = x1;
            p1.Y = 510 - y1;
            p2.X = x2;
            p2.Y = 510 - y2;
            p3.X = 510;
            p3.Y = 0;

            g.FillRectangle(new SolidBrush(Color.White), 0, 0, 510, 510);
            g.DrawLine(pen1, 0, 510, 510, 510);
            g.DrawLine(pen1, 0, 0, 0, 510);
            pen1.Color = Color.Red;
            g.DrawLine(pen1, p0, p1);
            g.DrawLine(pen1, p1, p2);
            g.DrawLine(pen1, p2, p3);

            g.DrawString("p1", Font, new SolidBrush(Color.Blue), x1 + 10, 510 - y1);
            g.DrawString("p2", Font, new SolidBrush(Color.Blue), x2 + 10, 510 - y2);
        }

        public string getX1 { get { return txtX1.Text.Trim(); } }

        public string getY1 { get { return txtY1.Text.Trim(); } }

        public string getX2 { get { return txtX2.Text.Trim(); } }

        public string getY2 { get { return txtY2.Text.Trim(); } }
    }
}
